﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TorneoLoL
{
    public partial class FormFixture : Form
    {
        Conexion conexion = new Conexion();
        DataSet dataS;

        public FormFixture()
        {
            InitializeComponent();
        }

        private void TreeView_DrawNode(object sender, DrawTreeNodeEventArgs e )
        {
            if(e.Node.Checked == true)
                e.DrawDefault = true;
        }

        private void FormFixture_Load( object sender, EventArgs e )
        {
            dataS = new DataSet();
            int i = 0, j;

            tvFixture.ExpandAll();
            System.Drawing.Size tam = new System.Drawing.Size( 700, 700 );
            tvFixture.Size = tam;
            tvFixture.Update();
            tvFixture.Indent = 80;

            try
            {
                conexion.consultarDataSet( ref dataS, "Partidas", "select * from Partidas where P_idGanador is not null" );
                while(dataS.Tables["Partidas"].Rows[i]["P_idGanador"].ToString() != null)
                {
                    j = i + 1;
                    while(dataS.Tables["Partidas"].Rows[j]["P_idGanador"].ToString() != null)
                    {
                        conexion.consultarDataSet( ref dataS, "Teams_1", "select * from Teams where T_IdTeam = " + dataS.Tables["Partidas"].Rows[i]["P_idGanador"].ToString() );
                        tvFixture.Nodes[0].FirstNode.FirstNode.FirstNode.FirstNode.Text = dataS.Tables["Teams_1"].Rows[0]["T_NombreTeam"].ToString();
                        conexion.consultarDataSet( ref dataS, "Teams_2", "select * from Teams where T_IdTeam = " + dataS.Tables["Partidas"].Rows[j]["P_idGanador"].ToString() );
                        tvFixture.Nodes[0].FirstNode.FirstNode.FirstNode.LastNode.Text = dataS.Tables["Teams_2"].Rows[0]["T_NombreTeam"].ToString();
                        i += 2;
                        dataS.Tables["Teams_1"].Clear();
                        dataS.Tables["Teams_2"].Clear();
                    }
                }
            }
            catch(System.IndexOutOfRangeException)
            {
                
            }
        }
    }
}
